import {Injectable, OnInit} from '@angular/core';
import { Behalf} from "../interface/behalf";
import {beHalfList} from "../mock/mock-behalf";
import { Observable, of } from 'rxjs';
@Injectable({
  providedIn: 'root'
})
export class BehalfService{

  constructor() { }

  beHalfList: Behalf[] = beHalfList;

  add(item:Behalf){
    this.beHalfList.push(item)
    console.log(this.beHalfList)
  }
  delete(id:number){
    this.beHalfList =  this.beHalfList.filter((item)=>item.id !== id)
    console.log(this.beHalfList)
  }
  getBehalfs():Observable<Behalf[]>{
    const beHalfList = of(this.beHalfList)
    return beHalfList
  }
  search(name:string){
    const isExist = this.beHalfList.find((item)=>item.createName == name)
    return isExist
  }

}
